<template>
<el-container>
    <el-aside width="200px">
       <MemberMenu></MemberMenu>
    </el-aside>
<div>
  <button class="taskCss" @click="departmentTask">部门任务状态</button> <button @click="enterpriseTask" >企业任务状态</button>
  <el-divider style="height:2px;background-color:gray;width:650px;margin-left:320px" />
<div v-if="showEdit"  class="formCss">
    
     <el-select class="select" v-model="value" placeholder="请选择任务状态">
     <el-option @click="unfinished" value="未完成"></el-option>
     <el-option @click="completed" value="已完成"></el-option>
     <el-option @click="submitted" value="已提交"></el-option>
     <button @click="ton" class="ton">清空</button>
  </el-select>
  <el-table :data="tasks" highlight-current-row @current-change="handleCurrentChange" style="width: 100%">
    <el-table-column label="序号" type="index" width="50"></el-table-column>
    <el-table-column prop="department.name" label="所在部门" width="120"></el-table-column>
    <el-table-column prop="project.name" label="项目名称" width="120"></el-table-column>
    <el-table-column prop="name" label="任务名称" width="120"></el-table-column>
    <el-table-column prop="details" label="任务详情" width="120"></el-table-column>
     <el-table-column prop="subTime" label="任务发布的时间"  width="120"></el-table-column>
  </el-table>
</div>
<div v-if="!showEdit" class="formCss">
  <el-select class="select" v-model="value" placeholder="请选择任务状态">
     <el-option @click="unfinishedCompany" value="未完成"></el-option>
     <el-option @click="completedCompany" value="已完成"></el-option>
     <el-option @click="submittedCompany" value="已提交"></el-option>
     <button @click="tonCompany" class="ton">清空</button>
  </el-select>
  <el-table :data="companyTasks" highlight-current-row @current-change="handleCurrentChange" style="width: 100%">
    <el-table-column label="序号" type="index" width="50"></el-table-column>
    <el-table-column prop="name" label="任务名称" width="120"></el-table-column>
    <el-table-column prop="details" label="任务详情" width="120"></el-table-column>
     <el-table-column prop="subTime" label="任务发布的时间"  width="120"></el-table-column>
  </el-table>
</div>
</div>
</el-container>
</template>
<script>
import MemberMenu from '@/components/menu/MemberMenu.vue'
import instance from '@/utlis/request.js'


export default {
    
    components: {
        MemberMenu,
        
    },
  
    data() {
        
        return {
        tasks:[],
        companyTasks:[],
        showEdit:true,
        };
    },
    
    //钩子函数   一般用来初始化数据
     created:function(){
      this.initData();
      this.initData1();
    },
     methods: {
     //显示页面所有的项目功能
      initData(){
        var companyUser=window.sessionStorage.getItem("companyUserId");
         var companyUserObj = JSON.parse(companyUser);
        console.log(companyUserObj);
        instance.get("task/member/list/"+companyUserObj).then(res=>{
          this.tasks=res.data.data;
          this.showEdit=true;
        })
      },
      //显示企业直接下发的所有项目的功能
      initData1(){
       var companyUser=window.sessionStorage.getItem("companyUserId");
        var companyUserObj = JSON.parse(companyUser);   
        instance.get("task/member/enterpriseTask/"+companyUserObj).then(res=>{
          this.companyTasks=res.data.data;
          this.showEdit=false;
        })
      },

      //项目未完成状态
      unfinished(){
       this.initData();
       this.showEdit=true;
      },
      //企业任务状态:项目未完成状态
      unfinishedCompany(){
         this.initData1();
         this.showEdit=false;
      },
      //项目已完成状态
      completed(){
        var companyUser=window.sessionStorage.getItem("companyUserId");
        var companyUserObj = JSON.parse(companyUser);
        instance.get("task/member/completedFindAll/"+companyUserObj).then(res=>{
          this.tasks=res.data.data;
          this.showEdit=true;
        })
      },
      //企业任务状态:已完成状态
      completedCompany(){
        var companyUser=window.sessionStorage.getItem("companyUserId");
        var companyUserObj = JSON.parse(companyUser);
        instance.get("task/member/completedCompanyFindAll/"+companyUserObj).then(res=>{
          this.companyTasks=res.data.data;
          this.showEdit=false;
        })
      },
      //项目已提交状态
      submitted(){
        var companyUser=window.sessionStorage.getItem("companyUserId");
        var companyUserObj = JSON.parse(companyUser);
        instance.get("task/member/submittedFindAll/"+companyUserObj).then(res=>{
          this.tasks=res.data.data;
          this.showEdit=true;
        })
      },
      //企业任务状态:已提交状态
      submittedCompany(){
       var companyUser=window.sessionStorage.getItem("companyUserId");
        var companyUserObj = JSON.parse(companyUser);
        instance.get("task/member/submittedCompanyFindAll/"+companyUserObj).then(res=>{
          this.companyTasks=res.data.data;
          this.showEdit=false;
        })
      },
      //下拉列表框的清空状态
      ton(){
         this.initData();
        this.showEdit=true;
        this.value="";
      },
      //企业任务状态下拉列表框的清空状态
      tonCompany(){
         this.initData1();
         this.showEdit=false;
         this.value="";
      },
      //部门任务状态
      departmentTask(){
         this.showEdit=true;
      },
      //企业任务状态
      enterpriseTask(){
         this.showEdit=false;
      }
      
    }

}
</script>
<style scoped>
  
    
    .formCss{
         width: 900px;
         margin-left: 320px;
    }

   .ton{
     margin-left: 180px;
   }
   .select{
     margin-top:30px;
   }

    .taskCss{
     margin-left: 322px;
     margin-top: 50px;
   }
</style>       